package org.ydsw.data.manage.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ydsw.data.manage.domain.PageHelperDataStandardReq;
import org.ydsw.data.manage.domain.PageHelperDomain;
import org.ydsw.data.manage.entity.DataManageStandardEntity;
import org.ydsw.data.manage.service.impl.DataManageStandardServiceImpl;
import org.ydsw.data.manage.utils.JsonResponse;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api")
public class DataMasterController {

    @Autowired
    DataManageStandardServiceImpl dataManageStandardService;

    @PostMapping("/dataMaster/findAll")
    public JsonResponse findAll(@RequestBody PageHelperDomain pageHelperDomain) {
        PageHelper.startPage(pageHelperDomain.getCurrent(), pageHelperDomain.getPageSize());
        List<DataManageStandardEntity> dataManageStandardEntities = dataManageStandardService.searchDataManageStandardAll();
        PageInfo<DataManageStandardEntity> pageInfos = new PageInfo<>(dataManageStandardEntities);
        return JsonResponse.respSuccess(pageInfos);
    }


    @GetMapping("/dataMaster/findStandardType")
    public JsonResponse selectDataStandardType() {
        List<DataManageStandardEntity> dataManageStandardEntities = dataManageStandardService.selectDataManageStandardType();

        List strList=new ArrayList();
        for (DataManageStandardEntity dataManageStandardEntity : dataManageStandardEntities) {
            strList.add(dataManageStandardEntity.getStandardType());
        }

        PageInfo<DataManageStandardEntity> pageInfos = new PageInfo<>(strList);

        return JsonResponse.respSuccess(pageInfos);
    }

    @PostMapping("/dataMaster/findStandardDetail")
    public JsonResponse selectStandardDetail(@RequestBody PageHelperDataStandardReq pageHelperDataStandard) {
        PageHelper.startPage(pageHelperDataStandard.getCurrent(), pageHelperDataStandard.getPageSize());
        List<DataManageStandardEntity> dataManageStandardEntities = dataManageStandardService.searchDataManageStandardTypeDetail(pageHelperDataStandard.getStandardType());
        PageInfo<DataManageStandardEntity> pageInfos = new PageInfo<>(dataManageStandardEntities);

        return JsonResponse.respSuccess(pageInfos);





    }




}
